﻿using System;

namespace CrmContrib.Workflow.Activities.Domain
{
    public class ContractLine
    {
        private double _percentageUsed;
        private string _contractLineSummary;

        public Guid Id { get; set; }
        public string Title { get; set; }
        public int AllotmentsUsed { get; set; }
        public int TotalAllotments { get; set; }
        public string AllotmentUnit { get; set; }
        public double PercentageUsed
        {
            get
            {
                if (_percentageUsed == default(Double))
                {
                    _percentageUsed = (TotalAllotments > 0) ? 100 * ((double)AllotmentsUsed / (double)TotalAllotments) : 0.0;
                    //_percentageUsed = Math.Round(_percentageUsed, 2);
                }
                return _percentageUsed;
            }
        }
        public string ContractLineSummary
        {
            get
            {
                if (String.IsNullOrEmpty(_contractLineSummary))
                {
                    _contractLineSummary = String.Format("{0}: {1} {3} out of {2} {3} have been used; ({4}%)", Title, AllotmentsUsed, TotalAllotments, AllotmentUnit, PercentageUsed.ToString("##0.00"));
                }
                return _contractLineSummary;
            }
        }
    }
}
